package main

import (
	"fmt"
	. "local/algorithm/util"
	"math"
)

func isValidBST(root *TreeNode) bool {
	return helper(root, int(math.MinInt), int(math.MaxInt))
}

func helper(root *TreeNode, min int, max int) bool {
	if root == nil {
		return true
	}

	if root.Val < min || root.Val > max {
		return false
	}

	return helper(root.Left, min, root.Val-1) && helper(root.Right, root.Val+1, max)
}

func main() {
	r := TreeNode{Val: 1, Left: nil, Right: nil}
	l := TreeNode{Val: 2, Left: nil, Right: nil}
	r.Left = &l
	fmt.Println(isValidBST(&r))
}
